<?php

require_once(DIR_LIB."VsImage".DIR_SEP."vsimage.php");

class VsGalleryImage extends VsImage {

	private static $_sqlTable='gallery_images';

	private $_id = 0;

	private $_parentId = 0; // Category Id
	private $_name = '';
	private $_image = '';
	private $_date = 0;

	private $_orderBy = 0;
	private $_enabled = 1;

	static function makeNew() {
		$img = &self::__construct();

		return $img;
	}
	//==========================================================================================================================

	static function makeFromDb($dbArray) {
		$img = &self::__construct(stripslashes($dbArray->image));

		$img->_id = $dbArray->id;
		$img->_parent = $dbArray->parent_id;
		$img->_image = stripslashes($dbArray->image);
		$img->_name = stripslashes($dbArray->name);
		$img->_date = $dbArray->date;

		$img->_orderBy = $dbArray->order_by;
		$img->_enabled = $dbArray->enabled;

		return $img;
	}
	//===========================================================================================================================

	static function makeFromForm($formArray) {

	}
	//==========================================================================================================================

	private function __construct($file) {
		parent::__construct($file);
	}
	//============================================================================================================================

	function id() { return $this->_id; }
	function parentId() { return $this->_parentId; }

	function image() { return $this->_image; }
	function name() { return $this->_name; }
	function date() { return $this->_date; }

	function orderBy() { return $this->_orderBy; }
	function enabled() { return $this->_enabled; }
	//=============================================================================================================================

	function delete() {
		if($this->_id<1)
			return;

		$q = "DELETE FROM `".self::$_sqlTable."` WHERE id=".$this->_id;

		$db = VsDatabase::Instance();
		$db->query($q);
	}
	//===================================================================================================================================

	function save() {
		if($this->_id > 0)
			$this->update();
		else
			$this->insert();
	}
	//==================================================================================================================================

	private function insert() {
		$q = "INSERT INTO `".self::$_sqlTable."` (`id`, `parent_id`, `name`, `image`, `date`, `ordered_by`, `enabled`) VALUES('', '0', '".$this->_name."', '".$this->_file->wwwPath()."', NOW(), '".$this->_orderedBy."', '".$this->_enabled."')";

		$db = VsDatabase::Instance();
		$db->query($q);
	}
	//==================================================================================================================================

	private function update() {
		$q = "UPDATE `".self::$_sqlTable."` WHERE id=".$this->_id;

		$db = VsDatabase::Instance();
		//$db->query($q);
	}
	//=================================================================================================================================

};

?>
